<?php 
class FormField extends Object
{
	public $Name;
	public $Label;
	public $Type;
	public $TypeTxt;
	public $Value;
	public $Values;
	public $MinLen;
	public $MaxLen;
	public $Params;
	public $ParamsLabel;
	public $Class;
	public $Show;
	public $Visible;
	public $Req;
	public $Nospace;
	public $ValidType;
	public $Compare;
	public $Error;
	public $Info;
	public $Valid;
	public $SrcTable;
	public $SrcLblSelect;
	public $SrcValSelect;
	public $SrcWhere;
	public $SrcValDef;
	public $SrcOrderBy;
	public $Options;
	public $Attributes;
	public $FieldOrder;
	public $Active;
	
	public function FormField($name='', $ty='', $lbl='', $show=1, $req=0, $nospace=false, $validt='anum', $mnl=0, $mxl=0, $comp='', $val='', $params=Array()) 
	{ 
		$this->Name = $name;
		if($ty != '')
		{ self::setType($ty); }
		self::setLabel($lbl);
		self::setShow($show);
		self::setVisible($show);
		self::setReq($req);
		self::setNospace($nospace);
		$this->ValidType = $validt;
		$this->MinLen = $mnl;
		$this->MaxLen = $mxl;
		$this->Compare = $comp;
		if(is_array($params) && (count($params) > 0))
		{ $this->Params = $params; }
		if($val != '')
		{ $this->Value = $val; }
		if($_REQUEST[$this->Name] != '')
		{ 
			if(is_array($_REQUEST[$this->Name]))
			{ $this->Value = $_REQUEST[$this->Name]; }
			else
			{ $this->Value = trim($_REQUEST[$this->Name]); }
		}
		if(is_array($_REQUEST[$this->Name]))
		{ 
			$this->Values = $_REQUEST[$this->Name]; 
			if(count($this->Values) > 0)
			{ $this->Value = implode('-', $this->Values); }
		}
	}
	
	public function getType($numeric=false) 
	{
		if($numeric == false)
		{ return $this->TypeTxt; }
		else
		{ return intval($this->Type); }
	}
	
	public function getLabelArray() 
	{
		$la = false;
		if(is_array($this->Label))
		{ $la = $this->Label; }
		else
		{ 
			if($this->Label != '')
			{ $la = explode(', ', $this->Label); }
		}
		return $la;
	}
	public function getValue() { return $this->Value; }
	public function getMaxLen() { return intval($this->MaxLen); }
	public function getMinLen() { return intval($this->MinLen); }
	public function getShow() { return intval($this->Visible); }
	public function getVisible() { return intval($this->Visible); }
	public function getReq() { return intval($this->Req); }
	public function getNospace() { return intval($this->Nospace); }
	public function getValid() { return intval($this->Valid); }
	public function getOptions() { return $this->Options;  }
	public function getFieldOrder() { return intval($this->FieldOrder);  }
	public function getActive() { return intval($this->Active);  }
	public function getParam($param='') 
	{ 
		if(isset($this->Params[$param]))
		{ return $this->Params[$param]; } 
	}
	public function getParamLabel($param='') 
	{ 
		if(isset($this->ParamsLabel[$param]))
		{ return $this->ParamsLabel[$param]; } 
	}
	public function getParamsLabel() 
	{ 
		if(self::getReq())
		{ $this->ParamsLabel['class'] .= ' req'; }
		if(self::getValid())
		{ $this->ParamsLabel['class'] .= ' valid'; }
		return $this->ParamsLabel;
	}
	
	public function setType($val) 
	{ 
		if(is_numeric($val))
		{
			$this->Type=intval($val);
			if($val == 0)
			{ 
				$this->TypeTxt = 'text';
				if(self::getValidType() == 'email')
				{ $this->TypeTxt = 'email'; }
			}
			if($val == 1)
			{ $this->TypeTxt = 'radio'; }
			if($val == 2)
			{ $this->TypeTxt = 'checkbox'; }
			if($val == 3)
			{ $this->TypeTxt = 'select'; }
			if($val == 4)
			{ $this->TypeTxt = 'textarea'; }
			if($val == 5)
			{ $this->TypeTxt = 'submit'; }
			if($val == 6)
			{ $this->TypeTxt = 'file'; }
			if($val == 7)
			{ $this->TypeTxt = 'button'; }
			if($val == 10)
			{ $this->TypeTxt = 'spacer'; }
			if($val == 11)
			{ $this->TypeTxt = 'label'; }
			if($val == 12)
			{ $this->TypeTxt = 'info'; }
		}
		else
		{
			$val = strtolower($val);
			switch($val)
			{
				case 'text':
				case 'password':
				case 'hidden':
				case 'file':
				case 'email':
				case 'tel':
					$this->Type=0;
					$this->TypeTxt = $val;
				break;
				case 'radio':
					$this->Type=1;
					$this->TypeTxt = $val;
				break;
				case 'checkbox':
					$this->Type=2;
					$this->TypeTxt = $val;
				break;
				case 'select':
					$this->Type=3;
					$this->TypeTxt = $val;
				break;
				case 'textarea':
					$this->Type=4;
					$this->TypeTxt = $val;
				break;
				case 'submit':
					$this->Type=5;
					$this->TypeTxt = $val;
				break;
				case 'button':
					$this->Type=7;
					$this->TypeTxt = $val;
				break;
				case 'spacer':
					$this->Type=10;
					$this->TypeTxt = $val;
				break;
				case 'label':
					$this->Type=11;
					$this->TypeTxt = $val;
				break;
				case 'info':
					$this->Type=12;
					$this->TypeTxt = $val;
				break;
			}
		}
	}
	public function setValue($val) { $this->Value=$val; }
	public function setMaxLen($val) { $this->MaxLen=intval($val); }
	public function setMinLen($val) { $this->MinLen=intval($val); }
	public function setShow($val) { $this->Show=$val; $this->Visible=$val; }
	public function setVisible($val) { $this->Visible=$val; }
	public function setReq($val) { $this->Req=intval($val); }
	public function setNospace($val) { $this->Nospace=intval($val); }
	public function setValidType($val) { $this->ValidType=$val; }
	public function setCompare($val) { $this->Compare=$val; }
	public function setValid($val) { $this->Valid=intval($val); }
	public function setActive($val) { $this->Active=intval($val); }
	public function setOptions($val) { $this->Options=$val; }
	public function setParam($param='', $val) 
	{ 
		if($param != '')
		{ $this->Params[$param]=$val; } 
	}
	public function setParamLabel($param='', $val) 
	{ 
		if($param != '')
		{ $this->ParamsLabel[$param]=$val; } 
	}
	
	public function validate()
	{
		global $txt;
		global $com; 
		
		self::setValid(1);
		self::setError('');
		
		if(self::getReq())
		{
			if((self::getValue() == '') || ($_REQUEST[self::getName()] == ''))
			{
				self::setError(ucfirst($txt->getWord('missing')));
				self::setValid(0);
			}
		}
		
		if(self::getValid())
		{
			if(self::getValue() != '')
			{
				if((self::getValidType() == 'text') || (self::getValidType() == 'txt'))
				{ self::setValue(self::formatText(self::getValue())); }
				if(self::getValidType() == 'html')
				{ self::setValue(self::formatHTML(self::getValue())); }
				if(self::getValidType() == 'url')
				{ self::setValue(self::formatRemoteUrl(self::getValue())); }
				
				if((self::getNospace() > 0) && ($com->hasSpace(self::getValue())) && ($this->Valid))
				{ 
					self::setError(ucfirst($txt->getWord('no_space_allowed')));
					self::setValid(0);
					self::setValue($com->stripSpace(self::getValue()));
				}
				if(($this->MinLen > 0) && (strlen(self::getValue()) < $this->MinLen) && ($this->Valid))
				{ 	
					self::setError(ucfirst($txt->getWord('must_have_min').' '.$this->MinLen.' '.$txt->getWord('chars')));
					self::setValid(0);
				}
				if((self::getMaxLen() > 0) && (strlen(self::getValue()) > self::getMaxLen()) && ($this->Valid))
				{ 
					self::setError(ucfirst($txt->getWord('can_have_max').' '.self::getMaxLen().' '.$txt->getWord('chars')));
					self::setValid(0);
					self::setValue(substr(self::getValue(), 0, self::getMaxLen()));
				}
				if((self::getValidType() == 'email') && ($com->isEmail(self::getValue()) == false) && ($this->Valid))
				{ 
					self::setError(ucfirst($txt->getWord('invalid').' '.$txt->getWord('e-mail')));
					self::setValid(0);
				}
				if(self::getValidType() == 'url')
				{ 
					if(self::getValue() == '')
					{
						self::setError(ucfirst($txt->getWord('invalid').' '.$txt->getWord('url')));
						self::setValid(0);
					}
				}
				if(((self::getValidType() == 'num') || (self::getValidType() == 'int')) && ($this->Valid) && (self::stripNonNumeric(self::getValue()) != self::getValue()))
				{ 
					self::setError(ucfirst($txt->getWord('valid_chars_num')));
					self::setValid(0);
					self::setValue(self::stripNonNumeric(self::getValue()));
				}
				if((self::getValidType() == 'anum') && ($this->Valid) && ($com->stripNonAlphaNum(self::getValue()) != self::getValue()))
				{ 
					self::setError(ucfirst($txt->getWord('valid_chars_anum')));
					self::setValid(0);
					self::setValue(self::stripNonAlphaNum(self::getValue()));
				}
				if((self::getValidType() == 'alpha') && ($this->Valid) && ($com->stripNonAlpha(self::getValue()) != self::getValue()))
				{ 
					self::setInfo(ucfirst($txt->getWord('valid_chars_alpha')));
					self::setValid(0);
					self::setValue(self::stripNonAlpha(self::getValue()));
				}
				if((trim(self::getCompare()) != '') && (self::getValue() != $_REQUEST[self::getCompare()]) && ($this->Valid))
				{ 
					self::setError(ucfirst($txt->getWord('values_do_not_match')));
					self::setValid(0);
				}
			}
		}
		return self::getValid();
	}
	
	public function addOption($value, $text='', $txt='', $params = Array())
	{
		$this->Options[$value]['value'] = $value;
		$this->Options[$value]['text'] = $text;
		$this->Options[$value]['txt'] = $txt;
		$this->Options[$value]['params'] = $params;
	}
	
	public function loadOptions()
	{
		if((self::getSrcTable() != '') && (self::getSrcValSelect() != ''))
		{
			global $db;
			
			$select = self::getSrcValSelect();
			if(self::getSrcLblSelect() != '')
			{ $select .= ', '.self::getSrcLblSelect(); }
			$sql = 'SELECT '.$select.' FROM '.DB_PERFIX.self::getSrcTable();
			if($this->SrcWhere != '')
			{ $sql .= ' WHERE '.$this->SrcWhere; }
			if($this->SrcOrderBy != '')
			{ $sql .= ' ORDER BY '.$this->SrcOrderBy; }
			$sql .= ';';
			
			$result = $db->query($sql);
			$data = $db->fetch($sql, self::getTTL());
			
			$result = mysql_query($sql);
			if(is_array($data))
			{
				foreach($data as $row)
				{
					$params = Array();
					$value = $row[self::getSrcValSelect()];
					if((self::getValue() == $row[self::getSrcValSelect()]) || ((self::getSrcValDef() != '') && (self::getSrcValDef() == $row[self::getSrcValSelect()]) && (self::getValue() == '')))
					{ $params['selected'] = 'selected'; } 
					
					if(self::getSrcLblSelect() != '')
					{ $text = $row[self::getSrcLblSelect()]; }
					else
					{ $text = $row[self::getSrcValSelect()]; }
					
					self::addOption($value, $text, '', $params);
				}
			}
		}
		else
		{
			if(self::getSrcValSelect() != '')
			{
				if((self::getSrcValSelect() == 'adc_colors') || (self::getSrcValSelect() == 'adc_list_colors'))
				{
					global $adc;
					if(is_object($adc))
					{
						$options = $adc->getSetting('Colors');
						if(is_array($options))
						{
							self::addOption(0, '', '--');
							foreach(array_keys($options) as $value)
							{
								$params = Array();
								$value = $value;
								$text  = $options[$value];
								
								if((self::getValue() == $value) || 
								   ((self::getSrcValDef() != '') && (self::getSrcValDef() == $value) && (self::getValue() == '')))
								{ $params['selected'] = 'selected'; } 
								self::addOption($value, '', $text, $params);
							}
						}
					}
				}
				else
				{
					$options = split(', ', self::getSrcValSelect());
					if(count($options > 0))
					{
						foreach($options as $option)
						{
							$vars = split('=', $option);
							if(count($vars) == 2)
							{
								$params = Array();
								$value = $vars[0];
								$text  = $vars[1];
								
								if((self::getValue() == $value) || ((self::getSrcValDef() != '') && (self::getSrcValDef() == $value) && (self::getValue() == '')))
								{ $params['selected'] = 'selected'; } 
						
								self::addOption($value, '', $text, $params);
							}
						}
					}
				}
			}
		}
	}
	
	public function getHTML($format='fieldset')
	{	
		global $txt;
		global $theme;
		if(((self::getValidType() == 'yes-no-na') || (self::getValidType() == 'yes-no')) && (!count($this->Options) > 0))
		{
			$this->Options[0]['value'] = 0;
			$this->Options[0]['txt'] = ucfirst($txt->getWord('no'));
			if(self::getValidType() == 'yes-no-na')
			{ $this->Options[0]['txt'] .= ' / '.ucfirst($txt->getWord('unknown')); }
			$this->Options[1]['value'] = 1;
			$this->Options[1]['txt'] = ucfirst($txt->getWord('yes'));
		}
		
		if(self::getVisible())
		{
			$class = self::getClass();
			if($class == '')
			{ $class = self::getType(); }
			if(self::getType() == 'password')
			{ $class .= ' text'; }
			if((self::getValidType() == 'num') || (self::getValidType() == 'numeric') || (self::getValidType() == 'int'))
			{ $class .= ' numeric'; }
			
			$outLabel = '';
			$outInfo = '';
			$outInputOpen = '';
			$outInput = '';
			$outInputClose = '';
			$outInfo2 = '';
			$out = '';
			
			if((self::getLabel()) && (self::getType(true) != 5) && (self::getType(true) != 7)) 
			{
				switch($format)
				{
					case 'fieldset':
						if(self::getParam('id') != '')
						{ $outLabel .= '<label for="'.self::getParam('id').'" '; }
						else
						{ $outLabel .= '<label for="'.self::getName().'" '; }
						if(self::getParamsLabel())
						{
							$keys = array_keys($this->ParamsLabel);
							foreach($keys as $key)
							{ 
								if($key != 'for')
								{ $outLabel .= $key.'="'.$this->ParamsLabel[$key].'" '; }
							}
						}	
						$outLabel .= '>';
					break;
					
					case 'table_lines':
						$outLabel .= '<td class="label ';
						if(self::getType(true) == 11)
						{ $outLabel .= self::getClass(); }
						if(self::getReq())
						{ $outLabel .= 'req'; }
						$outLabel .= '" ';
						if($this->ParamsLabel)
						{
							$keys = array_keys($this->ParamsLabel);
							foreach($keys as $key)
							{ $outLabel .= $key.'="'.$this->ParamsLabel[$key].'" '; }
						}	
						$outLabel .= '>';
					break;
				}
				
				switch($format)
				{
					case 'form_table_columns':
						$outLabel .= '<span class="label ';
						if(self::getType(true) == 11)
						{ $outLabel .= self::getClass(); }
						if(self::getReq())
						{ $outLabel .= 'req'; }
						$outLabel .= '" ';
						
						if($this->ParamsLabel)
						{
							$keys = array_keys($this->ParamsLabel);
							foreach($keys as $key)
							{ $outLabel .= $key.'="'.$this->ParamsLabel[$key].'" '; }
						}	
						$outLabel .= '>';
					break;
				}
				
				switch($format)
				{
					case 'fieldset':
					case 'table_lines':
					case 'form_table_columns':
						if(count(self::getLabelArray()) > 0)
						{
							$i=0;
							foreach(self::getLabelArray() as $lbl)
							{
								if($i == 0)
								{ $outLabel .= ucfirst($txt->getWord($lbl)); }
								else
								{ $outLabel .= ' '.$txt->getWord($lbl); }
								$i++;
							}
						}
						else
						{ $outLabel .= ucfirst($txt->getWord(self::getLabel())); }
						if(self::getReq())
						{ $outLabel .= '&nbsp;<span class="req">*</span>'; }
					break;
				}
				
				switch($format)
				{
					case 'fieldset':
						$outLabel .= '</label>';
					break;
					case 'table_lines':
						$outLabel .= '</td>';
					break;
					case 'form_table_columns':
						$outLabel .= '</span><br />';
					break;
				}
			}
			
			switch($format)
			{
				case 'fieldset':
				case 'form_table_columns':
					if(self::getError() != '')
					{ $outInfo .= '<div class="error alert alert-error help-inline">'.self::getError().' <button type="button" class="close" data-dismiss="alert">&times;</button></div>'; }
					if(self::getInfo())
					{ 
						$outInfo .= '<div class="info alert alert-info help-inline ';
						if(self::getType(true) == 12)
						{ 
							$outInfo .= ' '.self::getClass();
							if($option['params'])
							{
								$keys = array_keys($option['params']);
								foreach($keys as $key)
								{ $outInfo .= $key.'="'.$option['params'][$key].'" '; }
							}
						}
						$outInfo .= '"><i class="icon-info-sign">&nbsp;</i> '.self::getInfo().'</div><br />'; 
					}
				break;
				case 'table_lines':
					if((self::getError()) || (self::getInfo()))
					{
						$outInfo .= '<tr><td class="validation" colspan="2">';
						if(self::getError())
						{ $outInfo .= '<span class="error">'.self::getError().'</span>'; }
						if(self::getInfo())
						{ $outInfo .= '<span class="info">'.self::getInfo().'</span>'; }
						$outInfo .= '</td></tr>'; 
					}
					$outInfo .= '<tr>'; 
				break;
			}
			
			if($format == 'table_lines')
			{ $outInputOpen = '<td class="input">'; }
			
			switch(self::getType(true))
			{
				case 0: //text, password, hidden
					$outInput .= '<input name="'.self::getName().'" type="'.self::getTypeTxt().'" value="'.self::getValue().'" ';
					if(self::getId() != '')
					{ $outInput .=  ' id="'.self::getId().'" '; }
					if(self::getMaxLen() > 0)
					{ $outInput .=  ' maxlength="'.self::getMaxLen().'" '; }
					if($class != '')
					{ $outInput .=  ' class="'.$class.' form-control" '; }
					if(self::getReq())
					{ $outInput .= ' required="required" '; }
					if($this->Params)
					{
						$keys = array_keys($this->Params);
						foreach($keys as $key)
						{ $outInput .= $key.'="'.$this->Params[$key].'" '; }
					}	
					$outInput .=  ' />';
				break;
				
				case 1: //radio
					self::loadOptions();
					if(is_array($this->Options))
					{
						if(stristr($this->Class, 'jqUiRadio'))
						{
							$outInput .= '<div class="jqUiRadio">';
								foreach($this->Options as $option)
								{
									$outInput .= 		'<input type="radio" value="'.$option['value'].'" name="'.self::getName().'"';
													if((self::getValue() == $option['value']) || ((self::getSrcValDef() != '') && (self::getSrcValDef() == $option['value']) && (self::getValue() == '')))
													{ $outInput .= ' checked="checked" '; } 
													
									if($option['params'])
									{
										$keys = array_keys($option['params']);
										foreach($keys as $key)
										{ $outInput .= $key.'="'.$option['params'][$key].'" '; }
									}	
									$outInput .=  		' />';
									
									$outInput .=	'<label for="';
									if($option['params']['id'])
									{ $outInput .= $option['params']['id']; }
									else
									{ $outInput .= self::getName(); }
									$outInput .= '">';
									if($option['txt'])
									{ $outInput .= ucfirst($txt->getWord($option['txt']));; }
									else
									{ $outInput .= $option['text']; }
									$outInput .=	'</label>';
									
								}
							$outInput .= '</div>';
						}
						else
						{
							if(stristr($this->Class, 'btn-group'))
							{
								if($theme->getBootstrap() > 2)
								{ $outInput .= '<div class="'.$this->Class.'" data-toggle="buttons">'; }
								else
								{ $outInput .= '<div class="'.$this->Class.'" data-toggle="buttons-radio">'; }
								foreach($this->Options as $option)
								{
									//<button type="button" class="btn btn-primary">Left</button>
									if($theme->getBootstrap() > 2)
									{
  										$outInput .= '<label ';
										if($option['params'])
										{
											$keys = array_keys($option['params']);
											foreach($keys as $key)
											{ $outInput .= $key.'="'.$option['params'][$key].'" '; }
										}	
										$outInput .= '>';
										
										$outInput .= '<input type="radio" value="'.$option['value'].'" name="'.self::getName().'"';
										if((self::getValue() == $option['value']) || ((self::getSrcValDef() != '') && (self::getSrcValDef() == $option['value']) && (self::getValue() == ''))) 
										{
											$outInput .= ' checked="checked" '; 
											$option['params']['class'] .= 'active'; 
										} 
										$outInput .= '>';
										
										if($option['txt'])
										{ $outInput .= ucfirst($txt->getWord($option['txt']));; }
										else
										{ $outInput .= $option['text']; }
										$outInput .= '</label>';
									}
									else
									{
										$outInput .= '<button value="'.$option['value'].'" name="'.self::getName().'"';
										
										if((self::getValue() == 'submit') || (self::getName() == 'submit'))
										{ $outInput .= ' type="submit"'; }
										else
										{ $outInput .= ' type="button"'; }
										
										if((self::getValue() == $option['value']) || ((self::getSrcValDef() != '') && (self::getSrcValDef() == $option['value']) && (self::getValue() == ''))) 
										{
											$outInput .= ' checked="checked" '; 
											$option['params']['class'] .= 'active'; 
										} 
														
										if($option['params'])
										{
											$keys = array_keys($option['params']);
											foreach($keys as $key)
											{ $outInput .= $key.'="'.$option['params'][$key].'" '; }
										}	
										$outInput .= '>';
										
										if($option['txt'])
										{ $outInput .= ucfirst($txt->getWord($option['txt']));; }
										else
										{ $outInput .= $option['text']; }
										$outInput .=	'</button>';
									}
									
								}
								$outInput .= '</div>';
							}
							else
							{
								if((BOOTSTRAP > 0) || ($theme->getBootstrap() > 0))
								{
									foreach($this->Options as $option)
									{
										$outInput .=	'<label ';
										if($option['params']['id'])
										{ $outInput .= ' for="'.$option['params']['id'].'"'; }
										else
										{ $outInput .= ' for="'.self::getName().'"'; }
										if($this->Params)
										{
											$keys = array_keys($this->Params);
											foreach($keys as $key)
											{ $outInput .= $key.'="'.$this->Params[$key].'" '; }
										}
										$outInput .= ' class="'.$this->Class.'"';
										$outInput .= '>';
										
										$outInput .= 		'<input type="radio" value="'.$option['value'].'" ';
										
										if(count($this->Options) > 1)
										{ $outInput .= 		'name="'.self::getName().'[]" '; }
										else
										{ $outInput .= 		'name="'.self::getName().'" '; }
										
										if((self::getValue() == $option['value']) || ((self::getSrcValDef() != '') && (self::getSrcValDef() == $option['value']) && (self::getValue() == '')))
										{ $outInput .= ' checked="checked" '; } 
														
										if($option['params'])
										{
											$keys = array_keys($option['params']);
											foreach($keys as $key)
											{ $outInput .= $key.'="'.$option['params'][$key].'" '; }
										}	
										$outInput .=  		' /> ';
										if($option['txt'])
										{ $outInput .= ucfirst($txt->getWord($option['txt']));; }
										else
										{ $outInput .= $option['text']; }
										$outInput .=	'</label>';
										
									}
								}
								else
								{
									$outInput .= '<table cellpadding="0" border="0" cellspacing="0" class="radio-table '.self::getClass().'">';
									foreach($this->Options as $option)
									{
										$outInput .= '<tr>';
										$outInput .= 	'<td valign="bottom" align="right">';
										$outInput .= 		'<input type="radio" value="'.$option['value'].'" name="'.self::getName().'"';
														if((self::getValue() == $option['value']) || ((self::getSrcValDef() != '') && (self::getSrcValDef() == $option['value']) && (self::getValue() == '')))
														{ $outInput .= ' checked="checked" '; } 
										$outInput .=  		' />';
										$outInput .= 	'</td>';
										$outInput .= 	'<td valign="bottom" align="left">&nbsp;';
										if($option['txt'])
										{ $outInput .= ucfirst($txt->getWord($option['txt']));; }
										else
										{ $outInput .= $option['text']; }
										$outInput .= 	'</td>';
										$outInput .= '</tr>';
									}
								}
							}
							$outInput .= '</table>';
						}
					}
				break;
				
				case 2: //checkbox
					$outInput .= self::getCheckboxHTML($format);
				break;
				
				case 3:
					$class = $class.' form-control';
					$outInput .= '<select name="'.self::getName().'" ';
					if($this->Id != '')
					{ $outInput .=  ' id="'.$this->Id.'" '; }
					if($class != '')
					{ $outInput .=  ' class="'.$class.'" '; }
					if($this->Params)
					{
						$keys = array_keys($this->Params);
						foreach($keys as $key)
						{ $outInput .= $key.'="'.$this->Params[$key].'" '; }
					}	
					if(self::getReq())
					{ $outInput .= ' required="required" '; }
					$outInput .= '>';
					self::loadOptions();
					if(is_array($this->Options))
					{
						foreach($this->Options as $option)
						{
							$outInput .= '<option value="'.$option['value'].'" ';
							if((self::getValue() == $option['value']) || ((self::getSrcValDef() != '') && (self::getSrcValDef() == $option['value']) && (self::getValue() == '')))
							{ $outInput .= ' selected="selected" '; } 
							
							$outInput .= '>';
							
							if($option['txt'])
							{ $outInput .= ucfirst($txt->getWord($option['txt']));; }
							else
							{ $outInput .= $option['text']; }
							$outInput .= '</option>';
						}
					}
					$outInput .= '</select>';
				break;
				
				case 4:
					$class = $class.' form-control';
					$outInput .= '<textarea name="'.self::getName().'" ';
					if($this->Id != '')
					{ $outInput .=  ' id="'.$this->Id.'" '; }
					
					if($class != '')
					{ 
						$outInput .=  ' class="';
						$outInput .=  $class;
						if(self::getMaxLen() > 0)
						{ $outInput .=  ' limitLen'; }
						$outInput .=  '" '; 
					}
					
					if(self::getMaxLen() > 0)
					{ $outInput .=  ' maxlength="'.self::getMaxLen().'" '; }
					
					if($this->Params)
					{
						$keys = array_keys($this->Params);
						foreach($keys as $key)
						{ $outInput .= $key.'="'.$this->Params[$key].'" '; }
					}	
					$outInput .=  '>'.$this->Value.'</textarea>';
				break;
				
				case 5: //5='submit'
					$outInput .= '<input name="'.self::getName().'" type="'.self::getTypeTxt().'" value="';
					if(count(self::getLabelArray()) > 0)
					{
						$i=0;
						foreach(self::getLabelArray() as $lbl)
						{
							if($i == 0)
							{ $outInput .= ucfirst($txt->getWord($lbl)); }
							else
							{ $outInput .= ' '.$txt->getWord($lbl); }
							$i++;
						}
					}
					else
					{ $outInput .= ucfirst($txt->getWord(self::getLabel())); }
					$outInput .= '" ';
					
					if(self::getId() != '')
					{ $outInput .=  ' id="'.self::getId().'" '; }
					if(self::getMaxLen() > 0)
					{ $outInput .=  ' maxlength="'.self::getMaxLen().'" '; }
					if($class != '')
					{ $outInput .=  ' class="'.$class.' btn btn-primary" '; }
					if($this->Params)
					{
						$keys = array_keys($this->Params);
						foreach($keys as $key)
						{ $outInput .= $key.'="'.$this->Params[$key].'" '; }
					}	
					$outInput .=  ' />';
				break;
				
				case 7:
					$outInput .= '<button '; //type="button" '; //name="'.self::getName().'" value="'.self::getValue().'"';
					if((self::getValue() == 'submit') || (self::getName() == 'submit'))
					{ $outInput .= ' type="submit" name="submit"'; }
					else
					{ $outInput .= ' type="button" name="submit"'; }
					
					if(self::getId() != '')
					{ $outInput .=  ' id="'.self::getId().'" '; }
					if($class != '')
					{ $outInput .=  ' class="'.$class.' btn" '; }
					if($this->Params)
					{
						$keys = array_keys($this->Params);
						foreach($keys as $key)
						{ $outInput .= $key.'="'.$this->Params[$key].'" '; }
					}	
					$outInput .=  '>';
					if(count(self::getLabelArray()) > 0)
					{
						$i=0;
						foreach(self::getLabelArray() as $lbl)
						{
							if($i == 0)
							{ $outInput .= ucfirst($txt->getWord($lbl)); }
							else
							{ $outInput .= ' '.$txt->getWord($lbl); }
							$i++;
						}
					}
					else
					{ $outInput .= ucfirst($txt->getWord(self::getLabel())); }
					$outInput .=  '</button>';
				break;
				
				case 10:
					$outInput .= '<div class="form-field-v-space">&nbsp;</div>';
				break;
			}

			
			
			switch($format)
			{
				case 'fieldset':
					if((self::getType(true) != 5) && (self::getType(true) != 7))
					{ $outInputClose = '<div class="form-field-v-space">&nbsp;</div>'; }
				break;
				case 'table_lines':
					$outInputClose = '</td></tr>'; 
				break;
			}
			
			switch($format)
			{
				case 'table_cell':
					if(self::getError() != '')
					{ $outInfo2 = '<br /><span class="error">'.self::getError().'</span>'; }
					if(self::getInfo())
					{ $outInfo2 = '<br /><span class="info">'.self::getInfo().'</span>'; }
				break;
			}
			
			if((self::getValidType() == 'yes-no') && (self::getType(true) == 2) && (!($theme->getBootstrap() > 2)))
			{ $out = $outInfo.$outInputOpen.$outInput.$outLabel.$outInputClose.$outInfo2; }
			else
			{ 
				switch(self::getType(true))
				{
					case 0:
					case 3:
					case 4:
					case 5:
					case 7:
						if($theme->getBootstrap() > 2)
						{ 
							$out = '<div class="form-group';
							if(self::getError())
							{ $out .= ' has-error '; }
							$out .= '">';
							$out .= $outLabel.$outInfo.$outInputOpen.$outInput.$outInputClose.$outInfo2.'</div>'; }
						else
						{ $out = $outLabel.$outInfo.$outInputOpen.$outInput.$outInputClose.$outInfo2; }
					break;
					case 2:
						if($theme->getBootstrap() > 2)
						{ $out = $outInfo.$outInputOpen.$outInput.$outInputClose.$outInfo2; }
						else
						{ $out = $outLabel.$outInfo.$outInputOpen.$outInput.$outInputClose.$outInfo2; }
					break;
					default:
						$out = $outLabel.$outInfo.$outInputOpen.$outInput.$outInputClose.$outInfo2; 
					break;
				}
				
			}
			
			return $out;
		}
	}
	
	public function getCheckboxHTML($format='fieldset')
	{
		global $theme;
		global $txt;
		$outInput = '';
		self::loadOptions();
		if(is_array($this->Options))
		{
			if(stristr($this->Class, 'jqUi'))
			{
				$outInput .= '<div class="jqUiButtonset" ';
				if($this->Params)
				{
					$keys = array_keys($this->Params);
					foreach($keys as $key)
					{ $outInput .= $key.'="'.$this->Params[$key].'" '; }
				}	
				$outInput .= ' >';
				
				foreach($this->Options as $option)
				{
					$outInput .= 		'<input type="checkbox" value="'.$option['value'].'" ';
					
					if(count($this->Options) > 1)
					{ $outInput .= 		'name="'.self::getName().'[]" '; }
					else
					{ $outInput .= 		'name="'.self::getName().'" '; }
					
					if((self::getValue() == $option['value']) || ((self::getSrcValDef() != '') && (self::getSrcValDef() == $option['value']) && (self::getValue() == '')))
					{ $outInput .= ' checked="checked" '; } 
									
					if($option['params'])
					{
						$keys = array_keys($option['params']);
						foreach($keys as $key)
						{ $outInput .= $key.'="'.$option['params'][$key].'" '; }
					}	
					$outInput .=  		' />';
					
					$outInput .=	'<label for="';
					if($option['params']['id'])
					{ $outInput .= $option['params']['id']; }
					else
					{ $outInput .= self::getName(); }
					$outInput .= '">';
					if($option['txt'])
					{ $outInput .= ucfirst($txt->getWord($option['txt']));; }
					else
					{ $outInput .= $option['text']; }
					$outInput .=	'</label>';
					
				}
				$outInput .= '</div>';
			}
			else
			{
				if(self::getValidType() == 'yes-no')
				{
					if($theme->getBootstrap() > 2)
					{
						$outInput .=	'<div class="checkbox"><label ';
						if($option['params']['id'])
						{ $outInput .= ' for="'.$option['params']['id'].'"'; }
						else
						{ $outInput .= ' for="'.self::getName().'"'; }
						
						if($this->Params)
						{
							$keys = array_keys($this->Params);
							foreach($keys as $key)
							{ $outInput .= $key.'="'.$this->Params[$key].'" '; }
						}
						$outInput .= '>';
					}
					
					$outInput .= 		'<input type="checkbox" value="1" name="'.self::getName().'" ';
					if((self::getValue() > 0) || ((self::getSrcValDef() == 1) && (self::getValue() == '')))
					{ $outInput .= ' checked="checked" '; } 
					if($option['params'])
					{
						$keys = array_keys($option['params']);
						foreach($keys as $key)
						{ $outInput .= $key.'="'.$option['params'][$key].'" '; }
					}
									
					$outInput .=  		' />';
					
					if($theme->getBootstrap() > 2)
					{
						if(count(self::getLabelArray()) > 0)
						{
							$i=0;
							foreach(self::getLabelArray() as $lbl)
							{
								if($i == 0)
								{ $outInput .= ucfirst($txt->getWord($lbl)); }
								else
								{ $outInput .= ' '.$txt->getWord($lbl); }
								$i++;
							}
						}
						else
						{ $outInput .= ucfirst($txt->getWord(self::getLabel())); }
						
						$outInput .=	'</label></div>';
					}
				}
				else
				{
					if((BOOTSTRAP > 0) || ($theme->getBootstrap() > 0))
					{
						foreach($this->Options as $option)
						{
							$outInput .=	'<div class="checkbox"><label ';
							if($option['params']['id'])
							{ $outInput .= ' for="'.$option['params']['id'].'"'; }
							else
							{ $outInput .= ' for="'.self::getName().'"'; }
							
							if($this->Params)
							{
								$keys = array_keys($this->Params);
								foreach($keys as $key)
								{ $outInput .= $key.'="'.$this->Params[$key].'" '; }
							}
							$outInput .= '>';
							
							$outInput .= 		'<input type="checkbox" value="'.$option['value'].'" ';
							
							if(count($this->Options) > 1)
							{ $outInput .= 		'name="'.self::getName().'[]" '; }
							else
							{ $outInput .= 		'name="'.self::getName().'" '; }
							
							if((self::getValue() == $option['value']) || ((self::getSrcValDef() != '') && (self::getSrcValDef() == $option['value']) && (self::getValue() == '')))
							{ $outInput .= ' checked="checked" '; } 
											
							if($option['params'])
							{
								$keys = array_keys($option['params']);
								foreach($keys as $key)
								{ $outInput .= $key.'="'.$option['params'][$key].'" '; }
							}	
							$outInput .=  		' /> ';
							if($option['txt'])
							{ $outInput .= ucfirst($txt->getWord($option['txt']));; }
							else
							{ $outInput .= $option['text']; }
							$outInput .=	'</label></div>';
							
						}
					}
					else
					{
						$outInput .= '<table cellpadding="0" border="0" cellspacing="0" ';
						if($this->Params)
						{
							foreach(array_keys($this->Params) as $key)
							{ 
								if($key != 'class')
								{
									if($key != 'cols')
									{ $outInput .= $key.'="'.$this->Params[$key].'" '; }
									else
									{
										if(intval($this->Params['cols']) > 0)
										{ $outInput .= 	' style="width:100%"'; }
									}
								}
							}
						}
						if($this->Params['class'] != '')
						{ $outInput .= ' class="'.$this->Params['class'].' checkbox-table"'; }
						else
						{ $outInput .= ' class="checkbox-table"'; }
						
						$outInput .= 	'>';
						
						$outInput .= 	'<tr>';
						$i = 1;
						foreach($this->Options as $option)
						{
							$outInput .= 	'<td valign="bottom" >';
							$outInput .= 		'<input type="checkbox" value="'.$option['value'].'" ';
							if(count($this->Options) > 1)
							{ $outInput .= 		'name="'.self::getName().'[]" '; }
							else
							{ $outInput .= 		'name="'.self::getName().'" '; }
							
											if((self::getValue() == $option['value']) || ((self::getSrcValDef() != '') && (self::getSrcValDef() == $option['value']) && (self::getValue() == '')))
											{ $outInput .= ' checked="checked" '; } 
											if($option['params'])
											{
												$keys = array_keys($option['params']);
												foreach($keys as $key)
												{ $outInput .= $key.'="'.$option['params'][$key].'" '; }
											}
											
							$outInput .=  		' />';
							$outInput .= 	'</td>';
							$outInput .= 	'<td>&nbsp;</td>';
							$outInput .= 	'<td valign="bottom" align="left">';
							if($option['txt'])
							{ $outInput .= ucfirst($txt->getWord($option['txt']));; }
							else
							{ $outInput .= $option['text']; }
							$outInput .= 	'</td>';
							$outInput .= 	'<td>&nbsp;&nbsp;</td>';
							if(intval($this->Params['cols']) > 0)
							{
								if(($i % $this->Params['cols']) == 0)
								{ $outInput .= '</tr><tr>'; }
							}
							else
							{ $outInput .= '</tr><tr>'; }
							$i++;
						}
						$outInput .= 	'</tr>';
						$outInput .= '</table>';
					}
				}
			}
		}
		return $outInput;
	}
	
	public function getInputHTML($format='fieldset')
	{	
		global $txt;
		if(((self::getValidType() == 'yes-no-na') || (self::getValidType() == 'yes-no')) && (!count($this->Options) > 0))
		{
			$this->Options[0]['value'] = 0;
			$this->Options[0]['txt'] = ucfirst($txt->getWord('no'));
			if(self::getValidType() == 'yes-no-na')
			{ $this->Options[0]['txt'] .= ' / '.ucfirst($txt->getWord('unknown')); }
			$this->Options[1]['value'] = 1;
			$this->Options[1]['txt'] = ucfirst($txt->getWord('yes'));
		}
		if(self::getVisible())
		{
			$class = self::getClass();
			if($class == '')
			{ $class = self::getType(); }
			if(self::getType() == 'password')
			{ $class .= ' text'; }
			if((self::getValidType() == 'num') || (self::getValidType() == 'numeric') || (self::getValidType() == 'int'))
			{ $class .= ' numeric'; }
			
			$out = '';
			
			if(($format == 'table_lines') || ($format == 'table_inline'))
			{ $out .= '<td class="input">'; }
			
			switch(self::getType(true))
			{
				case 0: //text, password, hidden
					$out .= '<input name="'.self::getName().'" type="'.self::getTypeTxt().'" value="'.self::getValue().'" ';
					if(self::getId() != '')
					{ $out .=  ' id="'.self::getId().'" '; }
					if(self::getMaxLen() > 0)
					{ $out .=  ' maxlength="'.self::getMaxLen().'" '; }
					if($class != '')
					{ $out .=  ' class="'.$class.'" '; }
					if($this->Params)
					{
						$keys = array_keys($this->Params);
						foreach($keys as $key)
						{ $out .= $key.'="'.$this->Params[$key].'" '; }
					}	
					$out .=  ' />';
				break;
				
				case 1: //radio
					self::loadOptions();
					if(is_array($this->Options))
					{
						if(stristr($this->Class, 'jqUiRadio'))
						{
							$out .= '<div class="jqUiRadio">';
								foreach($this->Options as $option)
								{
									$out .= 		'<input type="radio" value="'.$option['value'].'" name="'.self::getName().'"';
													if((self::getValue() == $option['value']) || ((self::getSrcValDef() != '') && (self::getSrcValDef() == $option['value']) && (self::getValue() == '')))
													{ $out .= ' checked="checked" '; } 
													
									if($option['params'])
									{
										$keys = array_keys($option['params']);
										foreach($keys as $key)
										{ $out .= $key.'="'.$option['params'][$key].'" '; }
									}	
									$out .=  		' />';
									
									$out .=	'<label for="';
									if($option['params']['id'])
									{ $out .= $option['params']['id']; }
									else
									{ $out .= self::getName(); }
									$out .= '">';
									if($option['txt'])
									{ $out .= ucfirst($txt->getWord($option['txt']));; }
									else
									{ $out .= $option['text']; }
									$out .=	'</label>';
									
								}
							$out .= '</div>';
						}
						else
						{
							$out .= '<table cellpadding="0" border="0" cellspacing="0">';
							foreach($this->Options as $option)
							{
								$out .= '<tr>';
								$out .= 	'<td valign="bottom" align="right">';
								$out .= 		'<input type="radio" value="'.$option['value'].'" name="'.self::getName().'"';
												if((self::getValue() == $option['value']) || ((self::getSrcValDef() != '') && (self::getSrcValDef() == $option['value']) && (self::getValue() == '')))
												{ $out .= ' checked="checked" '; } 
								$out .=  		' />';
								$out .= 	'</td>';
								$out .= 	'<td valign="bottom" align="left">';
								if($option['txt'])
								{ $out .= ucfirst($txt->getWord($option['txt']));; }
								else
								{ $out .= $option['text']; }
								$out .= 	'</td>';
								$out .= '</tr>';
							}
							
							$out .= '</table>';
						}
					}
				break;
				
				case 2: //checkbox
					self::loadOptions();
					if(is_array($this->Options))
					{
						$out .= '<table cellpadding="0" border="0" cellspacing="0">';
						foreach($this->Options as $option)
						{
							$out .= '<tr>';
							$out .= 	'<td valign="bottom" align="right">';
							$out .= 		'<input type="checkbox" value="'.$option['value'].'" name="'.self::getName().'"';
											if((self::getValue() == $option['value']) || ((self::getSrcValDef() != '') && (self::getSrcValDef() == $option['value']) && (self::getValue() == '')))
											{ $out .= ' checked="checked" '; } 
							$out .=  		' />';
							$out .= 	'</td>';
							$out .= 	'<td valign="bottom" align="left">';
							if($option['txt'])
							{ $out .= ucfirst($txt->getWord($option['txt']));; }
							else
							{ $out .= $option['text']; }
							$out .= 	'</td>';
							$out .= '</tr>';
						}
						
						$out .= '</table>';
					}
				break;
				
				case 3:
					$out .= '<select name="'.self::getName().'" ';
					if($this->Id != '')
					{ $out .=  ' id="'.$this->Id.'" '; }
					if($class != '')
					{ $out .=  ' class="'.$class.'" '; }
					if($this->Params)
					{
						$keys = array_keys($this->Params);
						foreach($keys as $key)
						{ $out .= $key.'="'.$this->Params[$key].'" '; }
					}	
					$out .= '>';
					
					self::loadOptions();
					
					if(is_array($this->Options))
					{
						foreach($this->Options as $option)
						{
							$out .= '<option value="'.$option['value'].'" ';
							if((self::getValue() == $option['value']) || ((self::getSrcValDef() != '') && (self::getSrcValDef() == $option['value']) && (self::getValue() == '')))
							{ $out .= ' selected="selected" '; } 
							
							$out .= '>';
							
							if($option['txt'])
							{ $out .= ucfirst($txt->getWord($option['txt']));; }
							else
							{ $out .= $option['text']; }
							$out .= '</option>';
						}
					}
					
					$out .= '</select>';
				break;
				
				case 4:
					$out .= '<textarea name="'.self::getName().'" ';
					if($this->Id != '')
					{ $out .=  ' id="'.$this->Id.'" '; }
					
					if($class != '')
					{ 
						$out .=  ' class="';
						$out .=  $class;
						if(self::getMaxLen() > 0)
						{ $out .=  ' limitLen'; }
						$out .=  '" '; 
					}
					
					if(self::getMaxLen() > 0)
					{ $out .=  ' maxlength="'.self::getMaxLen().'" '; }
					
					if($this->Params)
					{
						$keys = array_keys($this->Params);
						foreach($keys as $key)
						{ $out .= $key.'="'.$this->Params[$key].'" '; }
					}	
					$out .=  '>'.self::getValue().'</textarea>';
				break;
				
				case 5:
					$out .= '<div class="form-field-v-space">&nbsp;</div>';
				break;
			}

			switch($format)
			{
				case 'fieldset':
					$out .= '<div class="form-field-v-space">&nbsp;</div>';
				break;
				case 'table_lines':
					$out .= '</td></tr>'; 
				break;
				case 'table_inline':
					$out .= '</td>'; 
				break;
			}
			return $out;
		}
	}
	
	public function getLabelHTML($format='fieldset')
	{	
		global $txt;
		if(((self::getValidType() == 'yes-no-na') || (self::getValidType() == 'yes-no')) && (!count($this->Options) > 0))
		{
			$this->Options[0]['value'] = 0;
			$this->Options[0]['txt'] = ucfirst($txt->getWord('no'));
			if(self::getValidType() == 'yes-no-na')
			{ $this->Options[0]['txt'] .= ' / '.ucfirst($txt->getWord('unknown')); }
			$this->Options[1]['value'] = 1;
			$this->Options[1]['txt'] = ucfirst($txt->getWord('yes'));
		}
		
		if(self::getVisible())
		{
			$out = '';
			if(self::getLabel())
			{
				switch($format)
				{
					case 'fieldset':
						if(self::getParam('id') != '')
						{ $out .= '<label for="'.self::getParam('id').'">'; }
						else
						{ $out .= '<label for="'.self::getName().'">'; }
					break;
					case 'table_lines':
						$out .= '<td class="label">';
					break;
				}
				
				switch($format)
				{
					case 'fieldset':
					case 'table_lines':
						if(count(self::getLabelArray()) > 0)
						{
							$i=0;
							foreach(self::getLabelArray() as $lbl)
							{
								if($i == 0)
								{ $out .= ucfirst($txt->getWord($lbl)); }
								else
								{ $out .= ' '.$txt->getWord($lbl); }
								$i++;
							}
						}
						else
						{ $out .= ucfirst($txt->getWord(self::getLabel())); }
						if(self::getReq())
						{ $out .= '&nbsp;<span class="req">*</span>'; }
						
						if($format == 'fieldset')
						{ $out .= '</label>'; }
						else
						{ $out .= '</td>'; }
					break;
				}
			}
			
			return $out;
		}
	}
	
	public function getLabelTxt()
	{	
		$out = '';
		if(self::getLabel())
		{
			global $txt;

			if(count(self::getLabelArray()) > 0)
			{
				$i=0;
				foreach(self::getLabelArray() as $lbl)
				{
					if($i == 0)
					{ $out .= ucfirst($txt->getWord($lbl)); }
					else
					{ $out .= ' '.$txt->getWord($lbl); }
					$i++;
				}
			}
			else
			{ $out .= ucfirst($txt->getWord(self::getLabel())); }
			if(self::getReq())
			{ $out .= '&nbsp;<span class="req">*</span>'; }
			
		}
		return $out;
	}
	
	public function getErrorHTML($format='fieldset')
	{	
		global $txt;
		if(self::getVisible())
		{
			$out = '';
			switch($format)
			{
				case 'fieldset':
					if(self::getError() != '')
					{ $out .= '<span class="error">'.self::getError().'</span><br />'; }
					if(self::getInfo())
					{ $out .= '<span class="info text-info">'.self::getInfo().'</span><br />'; }
				break;
				case 'table_lines':
					if((self::getError()) || (self::getInfo()))
					{
						$out .= '<tr><td class="validation" colspan="2">';
						if(self::getError())
						{ $out .= '<span class="error">'.self::getError().'</span>'; }
						if(self::getInfo())
						{ $out .= '<span class="info text-info">'.self::getInfo().'</span>'; }
						$out .= '</td></tr>'; 
					}
				break;
				case 'table_inline':
					if((self::getError() != '') || (self::getInfo() != ''))
					{
						$out .= '<td>';
							if(self::getError() != '')
							{ $out .= '<span class="error">'.self::getError().'</span>'; }
							if(self::getInfo())
							{ $out .= '<span class="info">'.self::getInfo().'</span>'; }
						$out .= '</td>'; 
					}
				break;
				case 'table_cell':
					if(self::getError() != '')
					{ $out .= '<br /><span class="error">'.self::getError().'</span>'; }
					if(self::getInfo())
					{ $out .= '<br /><span class="info">'.self::getInfo().'</span>'; }
				break;
			}
			return $out;
		}
	}
	
	public function getDataHTML($format='table')
	{	
		global $txt;
		if($this->Visible)
		{
			$class = $this->Class;
			if($class == '')
			{ $class = $this->Type; }
			if($this->Type == 'password')
			{ $class .= ' text'; }
			if(self::getValidType() == 'num')
			{ $this->Class .=' numeric'; }
			
			$out = '';
			
			if(self::getLabel())
			{ 
				if($format == 'fieldset')
				{ 
					if(self::getParam('id') != '')
					{ $out .= '<label for="'.self::getParam('id').'">'; }
					else
					{ $out .= '<label for="'.self::getName().'">'; }
				}
				else
				{ $out .= '<td class="label">'; } //Label Cell Start
				if(count(self::getLabelArray()) > 0)
				{
					$i=0;
					foreach(self::getLabelArray() as $lbl)
					{
						if($i == 0)
						{ $out .= ucfirst($txt->getWord($lbl)); }
						else
						{ $out .= ' '.$txt->getWord($lbl); }
						$i++;
					}
				}
				else
				{ $out .= ucfirst($txt->getWord(self::getLabel())); }
				
				if($format == 'fieldset')
				{ $out .= '</label>'; }
				else
				{ $out .= '</td>'; } //Label Cell End
			}
		
			
			//Value Cell Start
			if($format == 'table_lines')
			{ 
				$out .= '<td class="spacer">&nbsp;&nbsp;</td>'; 
				$out .= '<td class="value">'; 
			}
			
			if($this->Type == 'select')
			{
				self::loadOptions();
				if(is_array($this->Options))
				{
					foreach($this->Options as $option)
					{
						$out .= '<option value="'.$option['value'].'" ';
						if((self::getValue() == $option['value']) || ((self::getSrcValDef() != '') && (self::getSrcValDef() == $option['value']) && (self::getValue() == '')))
						{ $out .= ' selected="selected" '; } 
						
						$out .= '>';
						
						if($option['txt'])
						{ $out .= ucfirst($txt->getWord($option['txt']));; }
						else
						{ $out .= $option['text']; }
						$out .= '</option>';
					}
				}
				
				$out .= '</select>';
			}
			else
			{ $out .= self::getValue(); }
			if($format == 'table_lines')
			{ $out .= '</td>'; }
			//Value Cell End
			
			if($format == 'table_lines')
			{ $out .= '</tr>'; }
			else
			{ $out .= '<div class="form-field-v-space">&nbsp;</div>'; }
			return $out;
		}
	}
	
	function update()
	{
		if((self::getId() > 0) && (self::getDataChanged()))
		{
			$sql  = 'UPDATE '.DB_PERFIX.'fm_form_fields SET ';
			$sql .= '`name`="'.self::formatText(self::getName()).'", ';
			$sql .= '`label`="'.self::formatText(self::getLabel()).'", ';
			$sql .= '`info`="'.self::formatHtml(self::getInfo()).'", ';
			$sql .= '`class`="'.self::formatText(self::getClass()).'", ';
			$sql .= '`type`='.self::getType(true).', ';
			$sql .= '`visible`='.self::getVisible().', ';
			$sql .= '`req`='.self::getReq().', ';
			$sql .= '`minLen`='.self::getMinLen().', ';
			$sql .= '`maxLen`='.self::getMaxLen().', ';
			$sql .= '`nospace`='.self::getNospace().', ';
			$sql .= '`validType`="'.self::getValidType().'", ';
			$sql .= '`value`="'.self::getValue().'", ';
			$sql .= '`compare`="'.self::getCompare().'", ';
			$sql .= '`srcTable`="'.self::getSrcTable().'", ';
			$sql .= '`srcLblSelect`="'.self::getSrcLblSelect().'", ';
			$sql .= '`srcValSelect`="'.self::getSrcValSelect().'", ';
			$sql .= '`srcWhere`="'.self::getSrcWhere().'", ';
			$sql .= '`srcValDef`="'.self::getSrcValDef().'", ';
			$sql .= '`fieldOrder`='.self::getFieldOrder().', ';
			$sql .= '`active`='.self::getActive().' ';
			$sql .= ' WHERE id='.self::getId().' LIMIT 1;';
			//echo $sql;
			mysql_query($sql);
		}
	}
}
?>